package com.huawei.appgallery.assistantdock.base.externalaction.openviewaction;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import com.huawei.appgallery.assistantdock.buoydock.bean.BuoyForumMessageProfiles;
import com.huawei.appgallery.forum.message.api.ForumMessageHomeAction;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.List;
import o.beq;
import o.bfo;
import o.bvo;
import o.ces;
import o.cet;
import o.ceu;
import o.Logger;
import o.dys.a;
import o.ezo;
import o.ezs;
import o.fae;
import o.fam;

public class OpenForumMessageAction extends IOpenViewAction {
    private static final String ACTION_FORUM_MESSAGE_HOME = "com.huawei.appmarket.intent.action.forum.message.home";
    public static final String ACTION_OPEN_FORUM_MESSAGE = "com.huawei.gamebox.ACTION_OPEN_FORUM_MESSAGE";
    private static final String CLASS_NAME_THIRD_API = "com.huawei.appmarket.service.externalapi.view.ThirdApiActivity";
    private static final String HIAPP_PACKAGE_NAME = "com.huawei.appmarket";
    private static final String HIGAME_PACKAGE_NAME = "com.huawei.gamebox";
    public static final String REPORTBI_FORUMMSG_URI = "forum_msg";
    private static final int REQUEST_CODE = 9999;
    private static final String RESTORE_GAMEBOX_PATHJUDGE = "gamebox";
    private static final String TAG = "OpenForumMessageAction";
    private static MsgCallBack forumMsgCallBack;
    private static RestoreCallBack forumMsgRestoreCallBack;

    class ForumMsgRestoreCallback implements ces {
        public void onResult(int i) {
            Logger.ˎ(OpenForumMessageAction.TAG, "Restore result=" + i);
            beq.ˋ(i, "com.huawei.gamebox", OpenForumMessageAction.REPORTBI_FORUMMSG_URI);
            if (i == 2000 || i == 2001 || i == 2002) {
                OpenForumMessageAction.this.dispatchOpenForumMessage();
            } else if (i == 2100) {
                OpenForumMessageAction.excuteRestoreCallback();
                OpenForumMessageAction.this.callback.finish();
            } else if (i == 2300 || i == 2101 || i == 2102 || i == 2103 || i == 2301) {
                OpenForumMessageAction.this.callback.finish();
            }
        }
    }

    public interface MsgCallBack {
        void onGetMsg();
    }

    public interface RestoreCallBack {
        void onRestoreGetOnlineVersionFail();
    }

    public OpenForumMessageAction(a aVar, SafeIntent safeIntent) {
        super(aVar, safeIntent);
    }

    public void onAction() {
        if (this.callback instanceof Activity) {
            new ceu((Activity) this.callback).ˊ(new cet("com.huawei.gamebox", RESTORE_GAMEBOX_PATHJUDGE, 100100300), new ForumMsgRestoreCallback());
            return;
        }
        Logger.e(TAG, "callback is not Activity");
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == 9999 && i2 == -1) {
            dealWithData(intent);
        }
        this.callback.finish();
    }

    private void dealWithData(Intent intent) {
        SafeIntent safeIntent = new SafeIntent(intent);
        if (safeIntent.getBooleanExtra("result_success", false)) {
            BuoyForumMessageProfiles buoyForumMessageProfiles = new BuoyForumMessageProfiles();
            buoyForumMessageProfiles.ˋ(safeIntent.getIntExtra("replyMsgCnt", 0));
            buoyForumMessageProfiles.ˏ(safeIntent.getIntExtra("followMsgCnt", 0));
            buoyForumMessageProfiles.ˎ(safeIntent.getIntExtra("importantMsgCnt", 0));
            buoyForumMessageProfiles.ˊ(safeIntent.getIntExtra("likeMsgCnt", 0));
            buoyForumMessageProfiles.ʼ(safeIntent.getIntExtra("pushMsgCnt", 0));
            buoyForumMessageProfiles.ॱ(safeIntent.getIntExtra("growthMsgCnt", 0));
            bvo o_bvo = new bvo();
            o_bvo.ˎ(safeIntent.getBooleanExtra("replyMsgSwitch", false));
            o_bvo.ˊ(safeIntent.getBooleanExtra("likeMsgSwitch", false));
            o_bvo.ॱ(safeIntent.getBooleanExtra("followMsgSwitch", false));
            o_bvo.ˏ(safeIntent.getBooleanExtra("importantMsgSwitch", false));
            o_bvo.ˋ(safeIntent.getBooleanExtra("growthMsgSwitch", false));
            o_bvo.ॱॱ(safeIntent.getBooleanExtra("pushMsgSwitch", false));
            fae ˏ = fam.ॱ().ˏ();
            if (ˏ != null) {
                GameInfo gameInfo = ˏ.getGameInfo();
                if (gameInfo != null) {
                    ezo ˋ = ezs.ˏ().ˋ(gameInfo);
                    if (ˋ != null) {
                        ˋ.ॱ(o_bvo);
                        List<bfo> ˎ = ˋ.ˎ();
                        if (ˎ.size() != 0) {
                            for (bfo o_bfo : ˎ) {
                                if ("buoy_gss|forum_msg".equals(o_bfo.ˎ()) || "buoy_gss|forum_msg_v2".equals(o_bfo.ˎ())) {
                                    o_bfo.ˊ(buoyForumMessageProfiles);
                                }
                            }
                            notifyMsg();
                        } else {
                            return;
                        }
                    }
                }
            }
        }
        clearCallback();
    }

    private void dispatchOpenForumMessage() {
        if (this.callback instanceof Activity) {
            ezo gameBuoyEntryInfo = getGameBuoyEntryInfo();
            Intent intent = new Intent("com.huawei.appmarket.intent.action.forum.message.home");
            intent.setClassName("com.huawei.gamebox", CLASS_NAME_THIRD_API);
            intent.setPackage("com.huawei.gamebox");
            intent.putExtra(ForumMessageHomeAction.BUNDLE_SOURCETYPE, 2);
            if (gameBuoyEntryInfo != null) {
                intent.putExtra(ForumMessageHomeAction.BUNDLE_KINDID, gameBuoyEntryInfo.ᐝ());
            }
            try {
                this.callback.startActivityForResult(intent, 9999);
            } catch (ActivityNotFoundException e) {
                Logger.ˋ(TAG, "ActivityNotFoundException :" + e.toString());
            }
        }
    }

    private ezo getGameBuoyEntryInfo() {
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ != null) {
            return ezs.ˏ().ˋ(ˏ.getGameInfo());
        }
        return null;
    }

    public static synchronized void registerCall(MsgCallBack msgCallBack) {
        synchronized (OpenForumMessageAction.class) {
            forumMsgCallBack = msgCallBack;
        }
    }

    private static synchronized void notifyMsg() {
        synchronized (OpenForumMessageAction.class) {
            if (forumMsgCallBack != null) {
                forumMsgCallBack.onGetMsg();
            }
        }
    }

    private static synchronized void clearCallback() {
        synchronized (OpenForumMessageAction.class) {
            forumMsgCallBack = null;
            forumMsgRestoreCallBack = null;
        }
    }

    public static synchronized void registerRestoreCallback(RestoreCallBack restoreCallBack) {
        synchronized (OpenForumMessageAction.class) {
            forumMsgRestoreCallBack = restoreCallBack;
        }
    }

    private static synchronized void excuteRestoreCallback() {
        synchronized (OpenForumMessageAction.class) {
            if (forumMsgRestoreCallBack != null) {
                forumMsgRestoreCallBack.onRestoreGetOnlineVersionFail();
                forumMsgRestoreCallBack = null;
            }
        }
    }

    public boolean isFinishOnResume() {
        return false;
    }
}
